﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using Aricie.DNN.Modules.LuceneSearch.Business;
using Lucene.Net.Documents;

namespace Aricie.LuceneSearch.Tests.Components.Lucene
{

    public class FieldDefinitionTests
    {
        [Fact()]
        public void FieldDefinitionCanBeBuilt()
        {
            var FD = new FieldDefinition("rien");
        }

        [Fact(Skip="Ce test ne fonctionne pas encore car il utilise la Localization DNN")]
        public void FieldDefinitionFriendlyNameIsIdWithoutLocalization()
        {
            var FD = new FieldDefinition("rien");
            Assert.Equal(FD.Id, FD.FriendlyName);
        }

        [Fact()]
        public void FieldDefinitionDisplayIsCoherent()
        {
            var FDAnalyzed = new FieldDefinition("rien", Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO, false);
            FDAnalyzed.Displayed = false;
            FDAnalyzed.DisplayAsGroupable = false;
            FDAnalyzed.DisplayAsSearchable = false;
            FDAnalyzed.DisplayAsSortable = false;

            Assert.Equal(false, FDAnalyzed.Displayed);
            Assert.Equal(false, FDAnalyzed.DisplayAsGroupable);
            Assert.Equal(false, FDAnalyzed.DisplayAsSearchable);
            Assert.Equal(false, FDAnalyzed.DisplayAsSortable);

            FDAnalyzed.DisplayAsGroupable = true;
            Assert.Equal(false, FDAnalyzed.DisplayAsGroupable);

            FDAnalyzed.DisplayAsSearchable = true;
            Assert.Equal(false, FDAnalyzed.DisplayAsSearchable);

            FDAnalyzed.DisplayAsSortable = true;
            Assert.Equal(false, FDAnalyzed.DisplayAsSortable);

            FDAnalyzed.Displayed = true;
            Assert.Equal(true, FDAnalyzed.Displayed);
            Assert.Equal(true, FDAnalyzed.DisplayAsGroupable);
            Assert.Equal(true, FDAnalyzed.DisplayAsSearchable);
            Assert.Equal(true, FDAnalyzed.DisplayAsSortable);

            FDAnalyzed.DisplayAsGroupable = false;
            Assert.Equal(false, FDAnalyzed.DisplayAsGroupable);

            FDAnalyzed.DisplayAsSearchable = false;
            Assert.Equal(false, FDAnalyzed.DisplayAsSearchable);

            FDAnalyzed.DisplayAsSortable = false;
            Assert.Equal(false, FDAnalyzed.DisplayAsSortable);
        }

    }
}
